﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevEx.Thanh.Class;

namespace DevEx.Thanh.UserControl
{
    public partial class ucKiemTraSoLieu : DevExpress.XtraEditors.XtraUserControl
    {
        CTonController ctrlTon = new CTonController();
        public ucKiemTraSoLieu()
        {
            InitializeComponent();
        }

        private void ucKiemTraSoLieu_Load(object sender, EventArgs e)
        {
            CViewer.BindKhoToLookupEdit(lkeKho);
        }

        private void lkeKho_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                int maKho = Convert.ToInt32(lkeKho.EditValue);
                gridThongTinVatTu.DataSource = ctrlTon.KiemTraSoLieu(maKho);
            }
            catch (Exception)
            {
                gridThongTinVatTu.DataSource = null;
                //throw;
            }

        }

        private void btnDieuChinhSoLuong_Click(object sender, EventArgs e)
        {
            QLVTDataContext dc = new QLVTDataContext();
            int ID_Kho = (int)lkeKho.EditValue;
            var result = dc.sp_T_KiemTraSoLieu(ID_Kho);
            foreach(var r in result)
            {

                String strUpd = "UPDATE tblTON SET SLTONTH = SLTONKH, SLXUATTH = SLXUATKH, SLNHAPTH = SLNHAPKH WHERE ID_MATHANG = " + r.ID_MatHang.ToString();
                Thanh.Utilities.XL_DULIEU.ThucHienLenh(strUpd);
            }
            MessageBox.Show("Điều chỉnh số liệu xong.");
        }
    }
}
